<?php
	namespace App\Services\Push;

use App\Contracts\Pusher;
	
	
	class Gcm implements Pusher {
		protected $google_api_key = 'AIzaSyCsNkGA7GNFUOik6kB2zH-UL0bZSM_qUlw';
		protected $google_gcm_url = 'https://android.googleapis.com/gcm/send';

		public function push($msg){
			$headers = array(
				'Sender: id=' . 'thaifintech-80136',
				'Authorization: key=' . $this->google_api_key,
				'Content-Type: application/json'
			);
			
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $this->google_gcm_url);
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);

			$result = curl_exec($ch);

			curl_close($ch);

			$result = json_decode($result, true);
			if (isset($result['success']) && $result['success'] > 0) {
				return true;
			}

			return false;
		}
	}
